<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'maintain_detail.jsp' starting page</title>
	
<link rel="stylesheet" type="text/css" href="../../css/mokstyle.css" />
<link href="style1.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
//添加一行
	function addItem() {
		var detailTable = document.getElementById("detailTable");
		var oRow = detailTable.insertRow(-1);//在表格最后添加一行
		
		oRow.align = "center";
    	oRow.className ="toolbar";
    
		oCell = oRow.insertCell(0);//添加单元格
		oCell.innerHTML = oRow.rowIndex;

		oCell = oRow.insertCell(1);
		oCell.innerHTML = "<select name='wxbw' style='width: 117px'><option value='0'>请选择</option><option value='1'>发动机配件系列</option><option value='2'>制动零部件系列</option><option value='3'>汽车电器系列</option><option value='4'>汽车底盘</option><option value='5'>汽车车身</option></select>";

		oCell = oRow.insertCell(2);
		oCell.innerHTML = "<input type='text'  name='pjbh' size='10' readonly> <span class='LL'><a href='javascript:void(0)'  style='text-decoration:none'><image src='images/selectDate.gif' onClick='choiceParts(\""+(oRow.rowIndex-1)+"\")'></span></a>";
     
		oCell = oRow.insertCell(3);
		oCell.innerHTML = "<input type='text' name='pjmc' size='15' readonly>";

		oCell = oRow.insertCell(4);
		oCell.innerHTML = "<input type='text' name='sldw' size='10' readonly>";

		oCell = oRow.insertCell(5);
		oCell.innerHTML = "<input type='text' name='pjsl' size='10' onkeyup='textChanged();'>";

		oCell = oRow.insertCell(6);
		oCell.innerHTML = "<input type='text' name='xsdj' size='10' onkeyup='textChanged();'>";

		oCell = oRow.insertCell(7);
		oCell.innerHTML = "<input type='text' name='zj' size='10' readonly>";

		oCell = oRow.insertCell(8);
		oCell.innerHTML = '<a href="javascript:void(0)"  style="text-decoration:none"><image src="images/delete.gif" class="LL" onclick="delItem('+oRow.rowIndex+')"/></a>';
	}
	//删除行,注意这里的行号全部要重新计算 刷新的
	function delItem(index) {
		var detailTable = document.getElementById("detailTable");
		detailTable.deleteRow(index);
		var rowNum = detailTable.rows.length;
		var rowlength = detailTable.rows[0].cells.length;
		for (i=index; i<rowNum; i++) {
			detailTable.rows[i].cells[0].innerHTML = i;
			detailTable.rows[i].cells[rowlength-1].innerHTML = '<a href="javascript:void(0)"  style="text-decoration:none"><image src="images/delete.gif" class="LL" onclick="delItem('+i+')"/></a>';
			detailTable.rows[i].cells[2].innerHTML = "<input type='text'  name='pjbh' size='10' readonly value="+ document.mainFrm.pjbh[i-1].value +"> <span class='LL'><a href='javascript:void(0)'  style='text-decoration:none'><image src='images/selectDate.gif' onClick='choiceParts("+(i-1)+")'></span></a>";
		}
		textChanged();
	}
	function init(){
				if("${maintain}"!=""){
					var detailTable = document.getElementById("detailTable");
					var length = detailTable.rows.length;
					for (i=1; i<length; i++) {
						detailTable.rows[i].cells[0].innerHTML = i;
					}
		       		return;
		       }
					var d = new Date();
					var year = d.getFullYear();
					var month = d.getMonth() + 1;
					if((month/10)<1){
						month = "0"+month; 
					}
					var date = d.getDate();
					if((date/10)<1){
						date = "0"+date; 
					}
					var hour = d.getHours() ;
					if((hour/10)<1){
						hour = "0"+hour; 
					}
					var minutes = d.getMinutes() ;
					if((minutes/10)<1){
						minutes = "0"+minutes; 
					}
					var seconds = d.getSeconds() ;
					if((seconds/10)<1){
						seconds = "0"+seconds; 
					}
					document.getElementById('mtid').value = year+month+date+hour+minutes+seconds;
					document.getElementById('mtDate').value = year+"-"+month+"-"+date;
	
	}
	function choiceodd() {
		        var returnValue = window.showModalDialog("/aasimp/mok/maintenance/odd_choiceodd", null, "dialogHeight:400px; dialogWidth:600px; help:no; status:no");
		        if (returnValue==null){
		         	return;
		        } 
		        document.getElementById("oddId").value = returnValue[0];
		        document.getElementById("vin").value = returnValue[1];
    }
	function choiceParts(rowIndex) {
    	var detailTable = document.getElementById("detailTable");
    	var length = detailTable.rows.length;
        var returnValue = window.showModalDialog("/aasimp/mok/maintenance/part_choicepart", null, "dialogHeight:400px; dialogWidth:600px; help:no; status:no");
        if (returnValue==null) return;
        var pjbhs = document.getElementsByName("pjbh");
        for(var i=0;i<pjbhs.length;i++){
			if(pjbhs[i].value == returnValue[0]){
				alert("该配件已存在，请重新选择！");
				return;
			}
		}
        if (length>2) {
        	document.mainFrm.pjbh[rowIndex].value = returnValue[0];
            document.mainFrm.pjmc[rowIndex].value = returnValue[1];
            document.mainFrm.sldw[rowIndex].value = returnValue[2];
            document.mainFrm.xsdj[rowIndex].value = returnValue[3];
        } else {
            document.mainFrm.pjbh.value = returnValue[0];
            document.mainFrm.pjmc.value = returnValue[1];
            document.mainFrm.sldw.value = returnValue[2];
            document.mainFrm.xsdj.value = returnValue[3];
        }
    }
    function change(){
		var mtprice = document.getElementById("mtprice").value;
		if(!/^\d*\.?\d*$/.test(mtprice)){
			alert("请输入数字");
			document.getElementById("mtprice").value = "";
			mtprice = 0;
		}
		var ptprice = document.getElementById("ptprice").value;
		if(mtprice==""){
			mtprice = 0;
		}
		if(ptprice==""){
			ptprice = 0;
		}
		mtprice = parseFloat(mtprice);
		ptprice = parseFloat(ptprice);
		document.getElementById("mttotal").value = mtprice+ptprice;
    }
    function save(){
    	var vin = document.getElementById("vin").value;
    	if(vin==''){
    		alert("车辆识别号不能为空！");
    		return;
    	}
    	var mttotal = document.getElementById("mttotal").value;
    	if(mttotal==''){
    		document.getElementById("mttotal").value = 0;
    	}
    	var a = window.confirm("确认保存？");
    	if(!a)return;
    	document.getElementById("form1").submit();
    }
    function textChanged(){
		var pjsls = document.getElementsByName("pjsl");
		var xsdjs = document.getElementsByName("xsdj");
		var zjs = document.getElementsByName("zj");
		var ptprice = 0;
		for(var i=0;i<pjsls.length;i++){
					if(!/^\d*$/.test(pjsls[i].value)){
						alert("产品数量为整数！");
						pjsls[i].value = "";
						zjs[i].value = "";
					}
					if(!/^\d*\.?\d*$/.test(xsdjs[i].value)){
						alert("销售单价为数字！");
						xsdjs[i].value = "";
						zjs[i].value = "";
						
					}
			if(pjsls[i].value!="" && xsdjs[i].value!=""){
					zjs[i].value = pjsls[i].value*xsdjs[i].value;
					ptprice += pjsls[i].value*xsdjs[i].value;
			}else{
				zjs[i].value = "";
			}
		}
		document.getElementById("ptprice").value = ptprice;
		change();
	}
	function deleteRow(tr){
		index = tr.rowIndex;
		delItem(index);
	}
	function choiceRow(tr){
		index = tr.rowIndex;
		alert(index)
		choiceParts(index-1);
	}
</script>
  </head>
  
  <body onload="init();">
   <div  id="wrap">
 	<div class="header">
       		<div class="logo"><a href="/aasimp/mok/maintenance/index_getMtInfo"><img src="../../images/logo.gif" alt="" title="" border="0" /></a></div>            
        <div id="menu">
            <ul>                                                                       
            <li><a href="/aasimp/mok/maintenance/index_getMtInfo">首页</a></li>
            <li><a href="/aasimp/mok/maintenance/info_getcompany">个人资料</a></li>
            <li><a href="/aasimp/mok/maintenance/odd_getOdd" >维修申请</a></li>
            <li><a href="/aasimp/mok/maintenance/approve_showApprove">审批维修</a></li>
            <li class="selected"><a href="/aasimp/mok/maintenance/mt_showmts">维修记录</a></li>
            <li><a href="sendInfo.jsp">信息发布</a></li>
            <li><a href="/aasimp/mok/maintenance/report_showMtReport">报表统计</a></li>
            </ul>
        </div>  
       </div> 
       
       <div class="center_content" style="background-color:#FFFFFF;">
       	<div class="left_content" style="width: 880px">
       		<div class="crumb_nav">
            <a href="/aasimp/mok/maintenance/index_getMtInfo">home</a> &gt;&gt; <a href="maintain.jsp">维修记录</a> &gt;&gt; 维修记录详细
            </div>
            <div class="title"><span class="title_icon"><img src="../../images/bullet1.gif" alt="" title="" /></span>
            维修记录详细
            </div>
        <center>
        <div class="feat_prod_box_details" id="history" style="display: block;">
        <form id="form1" name="mainFrm" method="post" action="/aasimp/mok/maintenance/mt_saveMt">
<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="30px" nowrap class="toolbar">&nbsp;</td>
    <td width="70px" nowrap class="toolbar" onClick="document.mainFrm.mx.click()"><a href="javascript:void(0)"  style="text-decoration:none"><img src="images/add.gif">增加明细</a></td>
    <td width="20px" nowrap class="toolbar">|</td>
    <td width="40px" nowrap class="toolbar" onClick="document.mainFrm.bc.click()"><a href="javascript:void(0)"  style="text-decoration:none"><img src="images/save.gif">保存</a></td>
    <td width="20px" nowrap class="toolbar">|</td>
    <td width="40px" nowrap class="toolbar" onClick="document.mainFrm.gb.click()"><a href="javascript:void(0)"  style="text-decoration:none"><img src="images/cancel.gif">关闭</a></td>
	<td nowrap class="toolbar">&nbsp;</td>
  </tr>
</table>

<table id="headTable" width="100%"  border="0" align="center" class="a1">
  <tr align="justify">
    <td>维修单号</td>
    <td><input type="text" value="${maintain.maintainId }" size="15" readonly="readonly" name="mtid" id="mtid"/>
      </td>
    <td>预约单号</td>
    <td><input type="text" value="${maintain.oddId}" size="15" name="oddId" id="oddId"/>
      <span class='LL'><a href="javascript:void(0)"  style="text-decoration:none"><image src='images/selectDate.gif' onClick='choiceodd()'></a></span></td>
    <td>维修日期</td>
    <td><input name="mtDate" id="mtDate" type="text" size="15" value="${maintain.maintainDate}" readonly="readonly">
        </td>
    <td>维修公司</td>
    <td><input type="text" size="20" readonly="readonly" id="company" name="company" value="${companyInfo.companyName}"/>
      </td>
  </tr>
  <tr align="justify">
    <td>车辆识别号</td>
    <td><input id="vin" value="${maintain.vin}" type="text" size="15" name="vin"/><span class="requred_symbol">*</span>
       </td>
    <td>维修人员</td>
    <td><input type="text" size="15" readonly="readonly" name="person" id="person" value="${eauser.name}"/></td>
    <td>维修费用</td>
    <td><input type="text" value="${maintain.maintainPrice}" size="15" name="mtprice" id="mtprice" onkeyup="change()"/></td>
    <td>配件费用</td>
    <td><input type="text" value="${maintain.partsPrice}" size="20" readonly="readonly" name="ptprice" id="ptprice"/></td>
   </tr>
  <tr align="justify">
    <td>维修总费用</td>
    <td><input type="text" value="${maintain.toprice}" size="15" readonly="readonly" name="mttotal" id="mttotal"/></td>
    <td>维修结果</td>
    <td>
    	<select id="result" name="result" style="width: 117px">
    		<c:if test="${maintain.result =='1' }"><option selected="selected" value="1">成功</option></c:if>
    		<c:if test="${maintain.result !='1' }"><option value="1">成功</option></c:if>
    		<c:if test="${maintain.result =='0' }"><option selected="selected" value="0">报废</option></c:if>
    		<c:if test="${maintain.result !='0' }"><option value="0">报废</option></c:if>
    		<c:if test="${maintain.result =='2' }"><option selected="selected" value="2">再维修</option></c:if>
    		<c:if test="${maintain.result !='2' }"><option value="2">再维修</option></c:if>
    	</select><span class="requred_symbol">*</span>
    </td>
    <td>备注</td>
    <td colspan="3"><input type="text" size="49" name="remark" id="remark" value="${maintain.remark}"/></td>
   </tr>
  <tr>
  	<td class="title2"></td>
  </tr>
</table>
<table width="100%"  border="0" align="center" cellspacing="1" id="detailTable">
  <tr>
    <td class="toolbar"> 序号 </td>
    <td class="toolbar"> 维修部位 </td>
    <td class="toolbar"> 配件编号 </td>
    <td class="toolbar"> 配件名称 </td>
    <td class="toolbar"> 数量单位 </td>
    <td class="toolbar"> 配件数量 </td>
    <td class="toolbar"> 销售单价</td>
    <td class="toolbar"> 总价</td>
    <td class="toolbar">&nbsp;</td>
  </tr>
  <c:forEach var="item" items="${items}">
	  <tr>
	    <td align="center"></td>
	    <td align="center"><select name='wxbw' style='width: 117px'>
	    <c:if test="${item.itemsId==1}"><option value='1'>发动机配件系列</option></c:if>
	    <c:if test="${item.itemsId==2}"><option value='2'>制动零部件系列</option></c:if>
	    <c:if test="${item.itemsId==3}"><option value='3'>汽车电器系列</option></c:if>
	    <c:if test="${item.itemsId==4}"><option value='4'>汽车底盘</option></c:if>
	    <c:if test="${item.itemsId==5}"><option value='5'>汽车车身</option></c:if>
	    <option value='1'>发动机配件系列</option><option value='2'>制动零部件系列</option><option value='3'>汽车电器系列</option><option value='4'>汽车底盘</option><option value='5'>汽车车身</option>
	    </select></td>
	    <td align="center">
	    <input size="10" name='pjbh' readonly value="${item.partId}"/>
	    <a href='javascript:void(0)'  style='text-decoration:none'><image src="images/selectDate.gif" onClick="choiceRow(this.parentNode.parentNode.parentNode)"></a></td>
		<td align="center"><input name='pjmc' size='15' readonly value="${item.paetName }"/></td>
		<td align="center"><input name='sldw' size='10' readonly value="${item.unitname }"/></td>
	    <td align="center"><input name='pjsl' size='10' onkeyup='textChanged();' value="${item.num }"/></td>
	    <td align="center"><input name='xsdj' size='10' onkeyup='textChanged();' value="${item.unitprice }"/></td>
	    <td align="center"><input name='zj' size='10' value="${item.itemprice }"/></td>
	    <td align="center"><a href='javascript:void(0)'  style='text-decoration:none'><image src="images/delete.gif" class="LL" onclick="deleteRow(this.parentNode.parentNode.parentNode)"/></a></td>
	  </tr>
  </c:forEach>
</table>
<table width="100%"  border="0" align="center" cellspacing="1">
  <tr>
    <td class="title2"></td>
  </tr>
</table>
<br>
<div align="center">
    <input type="button" id="mx" value="增加明细" onClick="addItem()"/>
    <input type="button" id="bc" value="保存" onclick="save()"/>
    <input type="button" id="gb" value="关闭" onClick="window.location='/aasimp/mok/maintenance/mt_showmts'"/>
</div>
</form> 
	 </div>					
					</center>
            
            
        <div class="clear"></div>
        </div><!--end of left content-->
        
       
       <div class="clear"></div>
       </div><!--end of center content-->
       <div class="footer">
       	<div class="left_footer"><img src="../../images/footer_logo.gif" alt="" title="" /><br /> </div>
        <div class="right_footer">
       
        </div>
        
       
       </div>
    </div> 
<iframe width=174 height=189 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="calendar/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; left:-500px; top:0px;"></iframe>

  </body>
</html>
